﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management;
using System.Text;
using WMI.NET.Abstracts;
using WMI.NET.CIM;

namespace WMI.NET.ComputerSystemHardware.MassStorage
{
    /// <summary>
    /// The Win32_TapeDrive WMI class represents a tape drive on a computer system running Windows. Tape drives are primarily distinguished by the fact that they can only be accessed sequentially.
    /// </summary>
    public class Win32_TapeDrive : CIM_TapeDrive
    {

        private Nullable<UInt32> _Compression;
        private Nullable<UInt32> _ECC;
        private Nullable<UInt32> _FeaturesHigh;
        private Nullable<UInt32> _FeaturesLow;
        private string _Id;
        private string _Manufacturer;
        private string _MediaType;
        private Nullable<UInt32> _ReportSetMarks;

        /// <summary>
        /// If TRUE, hardware data compression is enabled.
        /// </summary>
        public Nullable<UInt32> Compression { get { return _Compression; } }

        /// <summary>
        /// If TRUE, the device supports hardware error correction.
        /// </summary>
        public Nullable<UInt32> ECC { get { return _ECC; } } //TODO enum

        /// <summary>
        /// High-order 32 bits of the device features flag.
        /// </summary>
        public Nullable<UInt32> FeaturesHigh { get { return _FeaturesHigh; } }

        /// <summary>
        /// Low-order 32 bits of the device features flag.
        /// </summary>
        public Nullable<UInt32> FeaturesLow { get { return _FeaturesLow; } }

        /// <summary>
        /// Manufacturer's identifying name of the Windows CD ROM drive.
        /// Example: "PLEXTOR CD-ROM PX-12CS 1.01"
        /// </summary>
        public string Id { get { return _Id; } }

        /// <summary>
        /// Manufacturer of the Windows CD-ROM drive.
        /// Example: "PLEXTOR"
        /// </summary>
        public string Manufacturer { get { return _Manufacturer; } }

        /// <summary>
        /// Media type used by (or accessed by) this device. In this case, it is set to "Tape Drive".
        /// </summary>
        public string MediaType { get { return _MediaType; } }

        /// <summary>
        /// If TRUE, setmark reporting is enabled. Setmark reporting makes use of a specialized recorded element that does not contain user data. This recorded element is used to provide a segmentation scheme that is hierarchically superior to filemarks. Setmarks provide faster positioning on high-capacity tapes.
        /// </summary>
        public Nullable<UInt32> ReportSetMarks { get { return _ReportSetMarks; } } //TODO enum

        /// <summary>
        /// 
        /// </summary>
        /// <param name="mbo"></param>
        public Win32_TapeDrive(ManagementBaseObject mbo)
            :base(mbo)
        {
            _Compression = mbo.GetUIntValue("Compression");
            _ECC = mbo.GetUIntValue("ECC");
            _FeaturesHigh = mbo.GetUIntValue("FeaturesHigh");
            _FeaturesLow = mbo.GetUIntValue("FeaturesLow");
            _Id = mbo.GetStringValue("Id");
            _Manufacturer = mbo.GetStringValue("Manufacturer");
            _MediaType = mbo.GetStringValue("MediaType");
            _ReportSetMarks = mbo.GetUIntValue("ReportSetMarks");
        }

    }

    /// <summary>
    /// 
    /// </summary>
    public class GetWin32_TapeDrives : Win32Collection<Win32_TapeDrive>
    {

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override ReadOnlyCollection<Win32_TapeDrive> GetCollection()
        {
            List<Win32_TapeDrive> tempCollection = new List<Win32_TapeDrive>();

            foreach (var s in searcher.Get())
            {
                Win32_TapeDrive tempListItem = new Win32_TapeDrive(s);
                tempCollection.Add(tempListItem);
            }

            return tempCollection.AsReadOnly();
        }

        /// <summary>
        /// 
        /// </summary>
        public GetWin32_TapeDrives() : base("SELECT * FROM Win32_TapeDrive") { }

    }

}
